package com.oocl.homework.crm.command;

import com.oocl.homework.crm.datastruct.Executeable;
import com.oocl.homework.crm.model.Filterable;

public class HelpCommand<T>  extends Command<T>{

	public HelpCommand(String command) {
		super(command);
	}
	
	@Override
	public void filter(Filterable filterable) {
		String[] commandparameter = command.split(" ");
		if (commandparameter.length>=1) {
			if (!commandparameter[0].equals("H")||commandparameter.length>2) {
				result.setCode(-1);
				result.setMessage("Unrecognized command:"+command);
				return;
			}
			
			if(commandparameter.length==2){
				String command = commandparameter[1];
				if (!(command.equals("A")||command.equals("D")||command.equals("L")||command.equals("O")||command.equals("U"))) {
					result.setCode(-1);
					result.setMessage("no command name:"+command);
					return;
				}
			}
			
		}
		
	}
	
	@Override
	public void executeCommand(Executeable<T> executeable, T t) {
		String[] commandparameter = command.split(" ");
		if (commandparameter.length==1) {
			CommandDoc.printHelp();
		}else{
			switch (commandparameter[1]) {
			case "A":
				CommandDoc.printAddCommandHelp();
				break;
			case "L":
				CommandDoc.printLookCommandHelp();
				break;
			case "U":
				CommandDoc.printUpdateCommandHelp();
				break;
			case "D":
				CommandDoc.printDeleteCommandHelp();
				break;
			case "O":
				CommandDoc.printOrderCommandHelp();
				break;
			default:
				break;
			}
		}
		
	}
	
	@Override
	public void display() {
		super.display();
//		CommandDoc.printHelp();
	}
	

}
